<template>
  <div>
    <time-line
      :time-line-list="timeLineList"
      :avatar="$store.state.webInfo.avatar"
      @launch="launch"
    >
    </time-line>
  </div>
</template>
<script>
import TimeLine from "@/components/love/timeLine.vue";

export default {
  components: {TimeLine},
  data() {
    return {
      timeLineList: [],
      pagination: {
        current: 1,
        size: 10,
        total: 0,
      },
    };
  },
  methods: {
    getTimeLinePage(){
      this.$createHttp.getTimeLinePage(this.pagination).then((res) => {
          if (res.code === 200) {
            res.data.records.forEach((c) => {
              c.content = c.content.replace(
                /\n{2,}/g,
                '<div style="height: 12px"></div>'
              );
              c.content = c.content.replace(/\n/g, "<br/>");
              c.content = this.$common.faceReg(c.content);
              c.content = this.$common.pictureReg(c.content);
            });
            this.timeLineList = this.timeLineList.concat(res.data.records);
            this.pagination.total = res.data.total;
          }
        })
        .catch((error) => {
          this.$message({
            message: error,
            type: "error",
          });
        });
    },
    launch() {
      if (this.pagination.total !== this.timeLineList.length) {
        this.pagination.current = this.pagination.current + 1;
        this.getTimeLinePage();
      } else {
        this.$message({
          message: "~~到底啦~~",
          type: "warning",
        });
      }
    },
  },
};
</script>
<style scoped>
</style>
